package xyz.penghaonan.p2plib.job.jobs;

import xyz.penghaonan.p2plib.job.base.BaseJob;
import xyz.penghaonan.p2plib.job.base.Operation;
import xyz.penghaonan.p2plib.job.base.OperationListener;
import xyz.penghaonan.p2plib.job.base.OperationListenerAdapter;
import xyz.penghaonan.p2plib.job.operations.DeleteGroupOperation;
import xyz.penghaonan.p2plib.job.operations.StopServiceOperation;

public class StopServerJob extends BaseJob {

    public StopServerJob() {
        DeleteGroupOperation operation = new DeleteGroupOperation();
        operation.addListener(new OperationListenerAdapter() {

            @Override
            public void onOperationFinish(Operation operation, Operation.Result result) {
                doStopServiceOperation();
            }
        });

        setHeaderOperation(operation);
    }

    private void doStopServiceOperation() {
        StopServiceOperation operation = new StopServiceOperation();
        operation.addListener(new OperationListenerAdapter() {

            @Override
            public void onOperationFinish(Operation operation, Operation.Result result) {
                notifyJobFinish(result.success, result.msg);
            }
        });
        executeOperation(operation);
    }
}
